package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.cty.ctyms.timejob.common.EquipVersionCommon;

public class VclCondayDAO {
	private IBaseDAO baseDAO;
	private ITransactionDAO tranDAO;
	
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}
	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}
	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}

	private String strSQL_A = "";
	private String strSQL_B = "";
	
	public void makeEngONRunKmOils(String tableDate) {
		this.trunData();
		//1.大一_定时参数信息
		this.strSQL_A = "select count(1) as counts from CTY_Egn_A.dbo.SysObjects Where XType='U' and Name=?";
		//2.小一_参数信息
		this.strSQL_B = "select count(1) as counts from CTY_Egn_B.dbo.SysObjects Where XType='U' and Name=?";		
		this.makeEngONRunKmOilsOfBoAll(tableDate);
		this.makeEngONRunKmOilsOfJ(tableDate);
		Map<String,Object> msgJP = baseDAO.execQueryOne(strSQL_B, new Object[]{"Msg_Timing_"+tableDate.replaceAll("-", "")+""});
		boolean isJP =false;
		if("1".equals(MapGetter.getString(msgJP,"counts"))){
			isJP = true;
		}
		//pgn参数
		Map<String,Object> msgUDS = baseDAO.execQueryOne(strSQL_B, new Object[]{"Msg_UDS_"+tableDate.replaceAll("-", "")+""});
		boolean uds = false;
		if("1".equals(MapGetter.getString(msgUDS,"counts"))){
			uds = true;
		}
		//pgn参数
		Map<String,Object> msgPgn = baseDAO.execQueryOne(strSQL_B, new Object[]{"Msg_PGN_"+tableDate.replaceAll("-", "")+""});
		boolean pgn = false;
		if("1".equals(MapGetter.getString(msgPgn,"counts"))){
			pgn = true;
		}
		this.makeEngONRunKmOilsOfPP(tableDate,isJP,uds);
		this.makeEngONRunKmOilsOfJPP(tableDate,isJP,pgn);
		this.makeNoMsg(tableDate);
		this.makeGPSDistance(tableDate);
		this.updateData();
		//增加最新设备累计参数统计方法--2014/05/16--FJC
		this.updateLastData();
		
	}
	
	/**
	 * 新增统计怠速耗油量
	 */
	private void insertIdleOilData(){
		Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
		 calendar.add(Calendar.DATE, -1);    //得到前一天
		 SimpleDateFormat sdfT = new SimpleDateFormat("yyyy-MM-dd");
		 String yeDayT = sdfT.format(calendar.getTime())+" 00:00:00.000";
		StringBuffer sb = new StringBuffer();
		sb.append("insert into Msg_Param_Last_Tmp");
	}
	/**
	 * 最新设备累计参数统计方法
	 */
	private void updateLastData(){
		Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
		 calendar.add(Calendar.DATE, -1);    //得到前一天
		 SimpleDateFormat sdfT = new SimpleDateFormat("yyyy-MM-dd");
		 String yeDayT = sdfT.format(calendar.getTime())+" 00:00:00.000";
		StringBuffer sb = new StringBuffer();
		sb.append("insert into Msg_Param_Last_Tmp");
		sb.append("(MsgSTP_VclID,MsgSTP_tEWorkHours,MsgSTP_tOilCons,msgstp_tidleOil,MsgSTP_tGPSDistance,MsgSTP_tMeterDistance,");
		sb.append("MsgSTP_tRunKmExact,MsgSTP_tRunKm,MsgSTP_tRunKmECU,MsgSTP_StatTime)");
		sb.append("select MsgSTP_VclID,");
		sb.append("ISNULL(ISNULL(MsgSTP_tEWorkHours,0)+ISNULL(MST_WorkHours,0),0) as MsgSTP_tEWorkHours,");
		sb.append("ISNULL(ISNULL(MsgSTP_tOilCons,0)+ISNULL(MST_OilCons,0),0) as MsgSTP_tOilCons,");
		sb.append("ISNULL(ISNULL(MsgSTP_tIdleOil,0)+ISNULL(MST_iIdleOil,0),0) as MsgSTP_tIdleOil,");
		sb.append("ISNULL(ISNULL(MsgSTP_tGPSDistance,0)+ISNULL(MST_tRunKmGPS,0),0) as MsgSTP_tGPSDistance,");
		sb.append("ISNULL(ISNULL(MsgSTP_tMeterDistance,0)+ISNULL(MST_tRunKmMeter,0),0) as MsgSTP_tMeterDistance,");
		sb.append("ISNULL(ISNULL(MsgSTP_tRunKmExact,0)+ISNULL(MST_tRunKmExact,0),0) as MsgSTP_tRunKmExact,");
		sb.append("ISNULL(ISNULL(MsgSTP_tRunKm,0)+ISNULL(MST_tRunKm,0),0) as MsgSTP_tRunKm,");
		sb.append("ISNULL(ISNULL(MsgSTP_tRunKmECU,0)+ISNULL(MST_tRunKmECU,0),0) as MsgSTP_tRunKmECU,");
		sb.append("GETDATE() as MsgSTP_StatTime from Message_Stat_TimingParam left join Message_Stat_Today on MsgSTP_VclID=MST_VclID ");
		sb.append("where MsgSTP_StatTime='"+yeDayT+"' ");
		int i = 0;
		try{
		i = baseDAO.execInsert(sb.toString(), new Object[]{});
		} catch(Exception e){
			System.out.print(e);
		}
		if(i>0){
			//执行成功，清空最新设备累计参数统计表
			String sql1 = "truncate table Msg_Param_Last";
			this.baseDAO.execUpdate(sql1, new Object[]{});
			//将临时表数据导入参数统计表中
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("insert into Msg_Param_Last");
			sbSql.append("(MsgSTP_VclID,MsgSTP_tEWorkHours,MsgSTP_tOilCons,MsgSTP_tIdleOil,MsgSTP_tGPSDistance,MsgSTP_tMeterDistance,");
			sbSql.append("MsgSTP_tRunKmExact,MsgSTP_tRunKm,MsgSTP_tRunKmECU,MsgSTP_StatTime)");
			sbSql.append("select MsgSTP_VclID,");
			sbSql.append("MsgSTP_tEWorkHours,");
			sbSql.append("MsgSTP_tOilCons,");
			sbSql.append("MsgSTP_tIdleOil,");
			sbSql.append("MsgSTP_tGPSDistance,");
			sbSql.append("MsgSTP_tMeterDistance,");
			sbSql.append("MsgSTP_tRunKmExact,");
			sbSql.append("MsgSTP_tRunKm,");
			sbSql.append("MsgSTP_tRunKmECU,");
			sbSql.append("MsgSTP_StatTime from Msg_Param_Last_Tmp");
			int j = baseDAO.execInsert(sbSql.toString(), new Object[]{});
			if(j>0){
				//执行成功，清空临时表
				String sql2 = "truncate table Msg_Param_Last_Tmp";
				this.baseDAO.execUpdate(sql2, new Object[]{});
			}
		}
		
	}
	/**
	 * GPS里程更新
	 **/
	private void makeGPSDistance(String tableDate) {
	    List<String> sqlGPS = new ArrayList<String>();
		String strSQL_GPS = "select count(1) as counts  from CTY_Vcl.dbo.SysObjects where XType = 'U' and Name =?";
		Map<String,Object> msgGPS = baseDAO.execQueryOne(strSQL_GPS, new Object[]{"Vcl_Pstn_"+tableDate.replaceAll("-", "")});
		if(!(msgGPS.get("counts").toString().equals("1"))){
			StringBuffer inullGPS  = new StringBuffer();
			inullGPS.append("update Message_Stat_Today_Tmp set MST_tRunKmGPS = 0 ;");
			sqlGPS.add(inullGPS.toString());
		}else{
			String strSQL="select MST_VclID as vclid from Message_Stat_Today_Tmp where MST_State = 2;";
			List<Map<String,Object>> list = baseDAO.execQuery(strSQL, new Object[]{});
			for(Map<String,Object> map:list){
				String vclid= MapGetter.getString(map,"vclid");
				if(StringUtil.isValid(vclid)){
					StringBuffer iupdateGPS = new StringBuffer();
					StringBuffer strGPSquery = new StringBuffer();
					strGPSquery.append(" select vp2.VclP_Vcl_ID as vclid,MAX(CAST(round(convert(float,ISNULL(vp2.VclP_IMileage,0))*1.0,2) as decimal(18,2))) as igpsdistance  ");
					strGPSquery.append(" from ((select VclP_Vcl_ID,max(vclp_id) as vclp_id  from CTY_Vcl.dbo.Vcl_Pstn_"+tableDate.replaceAll("-", ""));
					strGPSquery.append(" where VclP_MsgTp_ID=2 and vclp_imileage >0 and VclP_Vcl_ID='"+vclid+"' group by VclP_Vcl_ID ) as vp1 left join ");	
					strGPSquery.append(" (select vclp_id,VclP_Vcl_ID,VclP_IMileage = case when VclP_IMileage is NULL then 0 else VclP_IMileage end ");
					strGPSquery.append(" from CTY_Vcl.dbo.Vcl_Pstn_"+tableDate.replaceAll("-", "")+" ) vp2 on vp1.VclP_Vcl_ID = vp2.VclP_Vcl_ID and vp1.vclp_id = vp2.vclP_ID");
					strGPSquery.append(" ) GROUP BY vp2.VclP_Vcl_ID ");
					Map<String,Object> gpsmap = baseDAO.execQueryOne(strGPSquery.toString(), new Object[]{});
					String igpsdistance; 
					if(null != gpsmap.get("igpsdistance")){
						igpsdistance = gpsmap.get("igpsdistance").toString();
					}else{
						igpsdistance="0";
					}
					iupdateGPS.append("update Message_Stat_Today_Tmp set MST_tRunKmGPS = '"+igpsdistance+"' where MST_VclID = '"+vclid+"';");
					sqlGPS.add(iupdateGPS.toString());
				}				
			}
		}
		if(sqlGPS.size()!= 0){
			this.tranDAO.batch(sqlGPS);
		}
		StringBuffer strcheck = new StringBuffer();
		strcheck.append("update Message_Stat_Today_Tmp set MST_tRunKmGPS = 0 where MST_tRunKmGPS < 0");
		this.baseDAO.execUpdate(strcheck.toString(), new Object[]{});
	}
	
	private void makeNoMsg(String tTableDate) {
		String noMsg = "insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_StatTime,MST_State) " +
		"select VehicleID,0,0,0,0,0,0,0,0,?,2 from V_VehicleInfo where 1=1 and UsefulLife>=GETDATE() and not exists (select 1 from Message_Stat_Today_Tmp  mst where mst.MST_VclID = VehicleID) ";
		baseDAO.execInsert(noMsg, new Object[]{tTableDate});
	}
	private void makeEngONRunKmOilsOfJPP(String tTableDate,boolean isJP,boolean pgn) {
		String tableDate = tTableDate.replaceAll("-", "");
		//小一（JPP）
		String soJPPSoftVerTerm = EquipVersionCommon.getSoftVerByAgrType("Vcl_JPP");
		String soJPPStrSQL = "";
		if(isJP){
			soJPPStrSQL = "insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_StatTime,MST_State) " +
			"select tmp.VehicleID,ISNULL(tmp.MsgT_tWorkTime_UDS-tmp2.MsgT_tWorkTime_UDS,0) EngON," +
			"ISNULL(tmp.MsgT_tRunKm-tmp2.MsgT_tRunKm,0) RunKm," +
			"ISNULL(tmp.MsgT_tOilCons-tmp2.MsgT_tOilCons,0) Oils," +
			"ISNULL(tmp.msgt_tIdleOil - tmp2.msgt_tIdleOil,0) tIdleOil,"+
			"ISNULL(tmp.MsgT_tRunKmExact-tmp2.MsgT_tRunKmExact,0) tRunKmExact," +
			"ISNULL(tmp.tRunKm-tmp2.tRunKm,0) tRunKm," +
			"ISNULL(tmp.MsgT_tRunKmECU-tmp2.MsgT_tRunKmECU,0) tRunKmECU," +
			"ISNULL(tmp.MsgT_tRunKmExact_PGN-tmp2.MsgT_tRunKmExact_PGN,0) tRunKmExact_PGN," +
			"?,2 from ( " +
//			"SELECT VehicleID,MsgT_tRunKm = CASE WHEN MsgT_tRunKm IS NOT NULL  THEN MsgT_tRunKm WHEN MsgT_tRunKm IS NULL AND MsgT_tRunKmExact IS NOT NULL  THEN MsgT_tRunKmExact ELSE Isnull(MsgT_tRunKmECU,0) END, " +
            "SELECT VehicleID,MsgT_tRunKm = 0, " +
			"MsgT_tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tOilCons is not null and MsgT_tOilCons >0  order by MsgT_MsgTime desc), " +
			//"msgt_tIdleOil = CASE WHEN MsgT_tIdleWorkTime_PGN IS NOT NULL AND MsgT_tIdleWorkTime_PGN > 0 THEN MsgT_tIdleWorkTime_PGN ";
			//20140820 FJC 调整怠速油耗的取值
			"msgt_tIdleOil = isnull((select top 1  MsgT_tIdleWorkTime_PGN from  cty_egn_b.dbo.Msg_Timing_"+tableDate+" where msgt_vcl_id = vehicleid  AND MsgT_tIdleWorkTime_PGN IS NOT NULL  AND MsgT_tIdleWorkTime_PGN > 0 ORDER BY msgt_msgtime desc), ";
			if(pgn){
				soJPPStrSQL += " isnull((SELECT top 1 Convert(FLOAT,msgpc_pgnvalue) AS msgp_tidleoil FROM cty_egn_b.dbo.msg_pgn_"+tableDate+" INNER JOIN cty_egn_b.dbo.msg_pgn_content_"+tableDate+" ON msgp_id = msgpc_msgp_id WHERE msgp_vcl_id = vehicleid " +
						" and msgpc_syspip_id = 11 AND msgpc_syspi_id = 8  AND msgpc_pgnvalue IS NOT NULL AND Convert(FLOAT,msgpc_pgnvalue)>0 order by MsgP_MsgTime desc),0)),";
			}else{
				soJPPStrSQL += " 0 ),";
			}
			soJPPStrSQL +="MsgT_tWorkTime_UDS = (select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0  order by MsgT_MsgTime desc), " +
			"MsgT_tRunKmExact = (select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0  order by MsgT_MsgTime desc), " +
			"tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKm is not null and MsgT_tRunKm >0  order by MsgT_MsgTime desc),  " +
			"MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU  from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0  order by MsgT_MsgTime desc), " +
//			"MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN IS not null and MsgT_tRunKmExact_PGN >0 then MsgT_tRunKmExact_PGN ";
//			if(pgn){
//				soJPPStrSQL += " else isnull(MsgP_tMeterDis,0) end ";
//			}else{
//				soJPPStrSQL += " else 0 end ";
//			}
//			soJPPStrSQL +=" FROM V_VehicleInfo left join CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" on VehicleID= MsgT_Vcl_ID and MsgT_ID in (select MAX(MsgT_ID) from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN>0 group by MsgT_Vcl_ID) ";
//			if(pgn){
//				soJPPStrSQL += "left join ( SELECT MsgP_Vcl_ID, Convert(FLOAT,MsgPC_PGNValue) AS MsgP_tMeterDis FROM  CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" ON MsgP_ID = MsgPC_MsgP_ID  " +
//						"and MsgPC_ID in ( SELECT Max(MsgPC_ID) MsgPC_ID  From CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID = MsgPC_MsgP_ID  WHERE MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL  GROUP BY MsgP_Vcl_ID))temp_meter on temp_meter.MsgP_Vcl_ID = VehicleID ";
//			}
            "MsgT_tRunKmExact_PGN = isnull((select Top 1 MsgT_tRunKmExact_PGN from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" WHERE MsgT_Vcl_ID=VehicleID and MsgT_tRunKmExact_PGN IS NOT NULL AND MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime), ";
			if(pgn){
				soJPPStrSQL += "ISNULL((select top 1 MsgPC_PGNValue from CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" ON MsgP_ID = MsgPC_MsgP_ID  WHERE  MsgP_Vcl_ID = VehicleID and  MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime desc),0) ";
			}else{
				soJPPStrSQL += " 0 ";
			}
            soJPPStrSQL += " ) FROM V_VehicleInfo ";
            
			soJPPStrSQL += "where UsefulLife > GETDATE() and Tmnl_SoftEdition in ("+soJPPSoftVerTerm+"))tmp left join ( " +
//					"SELECT VehicleID,MsgT_tRunKm = CASE WHEN MsgT_tRunKm IS NOT NULL  THEN MsgT_tRunKm WHEN MsgT_tRunKm IS NULL AND MsgT_tRunKmExact IS NOT NULL  THEN MsgT_tRunKmExact ELSE Isnull(MsgT_tRunKmECU,0) END, " +
					"SELECT VehicleID,MsgT_tRunKm = 0, " +
					"MsgT_tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tOilCons is not null and MsgT_tOilCons >0  order by MsgT_MsgTime asc), " +
					"msgt_tIdleOil = isnull((select top 1  MsgT_tIdleWorkTime_PGN from  cty_egn_b.dbo.Msg_Timing_"+tableDate+" where msgt_vcl_id = vehicleid  AND MsgT_tIdleWorkTime_PGN IS NOT NULL  AND MsgT_tIdleWorkTime_PGN > 0 ORDER BY msgt_msgtime asc), ";
					if(pgn){
						soJPPStrSQL += " isnull((SELECT top 1 Convert(FLOAT,msgpc_pgnvalue) AS msgp_tidleoil FROM cty_egn_b.dbo.msg_pgn_"+tableDate+" INNER JOIN cty_egn_b.dbo.msg_pgn_content_"+tableDate+" ON msgp_id = msgpc_msgp_id WHERE msgp_vcl_id = vehicleid " +
								" and msgpc_syspip_id = 11 AND msgpc_syspi_id = 8  AND msgpc_pgnvalue IS NOT NULL AND Convert(FLOAT,msgpc_pgnvalue)>0 order by MsgP_MsgTime asc),0)),";
					}else{
						soJPPStrSQL += " 0 ),";
					}
					soJPPStrSQL +="MsgT_tWorkTime_UDS = (select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0  order by MsgT_MsgTime asc), " +
					"MsgT_tRunKmExact = (select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0  order by MsgT_MsgTime asc), " +
					"tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKm is not null and MsgT_tRunKm >0  order by MsgT_MsgTime asc), " +
					"MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU  from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0  order by MsgT_MsgTime asc), " +
					"MsgT_tRunKmExact_PGN = isnull((select Top 1 MsgT_tRunKmExact_PGN from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" WHERE MsgT_Vcl_ID=VehicleID and MsgT_tRunKmExact_PGN IS NOT NULL AND MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime), ";
//					"MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN IS not null and MsgT_tRunKmExact_PGN >0 then MsgT_tRunKmExact_PGN  ";
//			if(pgn){
//				soJPPStrSQL += " else isnull(MsgP_tMeterDis,0) end ";
//			}else{
//				soJPPStrSQL += " else 0 end ";
//			}
//			soJPPStrSQL += "FROM   V_VehicleInfo left join CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" on VehicleID= MsgT_Vcl_ID and MsgT_ID in (select MIN(MsgT_ID) from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN>0 group by MsgT_Vcl_ID) ";
//			if(pgn){
//				soJPPStrSQL += "left join ( SELECT MsgP_Vcl_ID, Convert(FLOAT,MsgPC_PGNValue) AS MsgP_tMeterDis FROM  CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" ON MsgP_ID = MsgPC_MsgP_ID  " +
//						"and MsgPC_ID in ( SELECT MIN(MsgPC_ID) MsgPC_ID  From CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID = MsgPC_MsgP_ID WHERE MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL  GROUP BY MsgP_Vcl_ID))temp_meter on temp_meter.MsgP_Vcl_ID = VehicleID ";
//			}
			if(pgn){
				soJPPStrSQL += "ISNULL((select top 1 MsgPC_PGNValue from CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" ON MsgP_ID = MsgPC_MsgP_ID  WHERE  MsgP_Vcl_ID = VehicleID and  MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime ),0) ";
			}else{
				soJPPStrSQL += " 0 ";
			}
			soJPPStrSQL += " ) FROM V_VehicleInfo ";
			soJPPStrSQL += " where UsefulLife > GETDATE() and Tmnl_SoftEdition in ("+soJPPSoftVerTerm+")) tmp2 ON tmp.VehicleID = tmp2.VehicleID ";
			/*"select MsgT_Vcl_ID," +
			"MsgT_tRunKm=case when MsgT_tRunKm is not null then MsgT_tRunKm when MsgT_tRunKm is null " +
			"and MsgT_tRunKmExact is not null then MsgT_tRunKmExact else ISNULL(MsgT_tRunKmECU,0) end,MsgT_tOilCons,MsgT_tWorkTime_UDS," +
			"MsgT_tRunKmExact,MsgT_tRunKm as tRunKm ,MsgT_tRunKmECU,MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN is not null then MsgT_tRunKmExact_PGN  ";
			if(pgn){
				soJPPStrSQL += " else isnull(pgn.MsgP_tMeterDis,0) end ";
			}else{
				soJPPStrSQL += " else 0 end ";
			}
			soJPPStrSQL +=" from CTY_Egn_B.dbo.Msg_Timing_"+tableDate; 
			if(pgn){
				soJPPStrSQL += "  left join (select MsgP_Vcl_ID,CONVERT(float,MsgPC_PGNValue) as MsgP_tMeterDis,MsgP_MsgTime from V_VehicleInfo  "+
						"left join CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" on MsgP_Vcl_ID=VehicleID  inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID=MsgPC_MsgP_ID  "+
						"inner join ( select MAX(MsgPC_ID)MsgPCID from CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID=MsgPC_MsgP_ID  "+
						"where MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null group by MsgP_Vcl_ID ) tmp on tmp.MsgPCID = MsgPC_ID )pgn on MsgT_Vcl_ID = MsgP_Vcl_ID ";
			}	
			soJPPStrSQL += "  where MsgT_ID in (" +
			"select MAX(MsgT_ID) from " +
			"CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
			"where (MsgT_tRunKmExact is not null or MsgT_tRunKm is not null or MsgT_tRunKmECU is not null) " +
			"and (MsgT_tRunKmExact>0 or MsgT_tRunKm>0 or MsgT_tRunKmECU>0) " +
			"and MsgT_tOilCons is not null and MsgT_tOilCons>0 " +
			"and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS>0 " +
			"and exists(select * from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE() " +
			"and Tmnl_SoftEdition in ("+soJPPSoftVerTerm+")) " +
			"group by MsgT_Vcl_ID)" +
			")tmp inner join (" +
			"select MsgT_Vcl_ID," +
			"MsgT_tRunKm=case when MsgT_tRunKm is not null then MsgT_tRunKm when MsgT_tRunKm is null " +
			"and MsgT_tRunKmExact is not null then MsgT_tRunKmExact else ISNULL(MsgT_tRunKmECU,0) end,MsgT_tOilCons,MsgT_tWorkTime_UDS," +
			"MsgT_tRunKmExact,MsgT_tRunKm as tRunKm ,MsgT_tRunKmECU,MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN is not null then MsgT_tRunKmExact_PGN  ";
			if(pgn){
				soJPPStrSQL += " else isnull(pgn.MsgP_tMeterDis,0) end ";
			}else{
				soJPPStrSQL += " else 0 end ";
			}
			soJPPStrSQL += "from CTY_Egn_B.dbo.Msg_Timing_"+tableDate;
			if(pgn){
				soJPPStrSQL += "  left join (select MsgP_Vcl_ID,CONVERT(float,MsgPC_PGNValue) as MsgP_tMeterDis,MsgP_MsgTime from V_VehicleInfo  "+
						"left join CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" on MsgP_Vcl_ID=VehicleID  inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID=MsgPC_MsgP_ID  "+
						"inner join ( select MIN(MsgPC_ID)MsgPCID from CTY_Egn_B.dbo.Msg_PGN_"+tableDate+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableDate+" on MsgP_ID=MsgPC_MsgP_ID  "+
						"where MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null group by MsgP_Vcl_ID ) tmp on tmp.MsgPCID = MsgPC_ID )pgn on MsgT_Vcl_ID = MsgP_Vcl_ID ";
			}
			soJPPStrSQL += "  where MsgT_ID in (" +
			"select MIN(MsgT_ID) from " +
			"CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
			"where (MsgT_tRunKmExact is not null or MsgT_tRunKm is not null or MsgT_tRunKmECU is not null) " +
			"and (MsgT_tRunKmExact>0 or MsgT_tRunKm>0 or MsgT_tRunKmECU>0) " +
			"and MsgT_tOilCons is not null and MsgT_tOilCons>0 " +
			"and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS>0 " +
			"and exists(select * from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE() " +
			"and Tmnl_SoftEdition in ("+soJPPSoftVerTerm+"))" +
			"group by MsgT_Vcl_ID)" +
			")tmp2 on tmp.MsgT_Vcl_ID=tmp2.MsgT_Vcl_ID";*/			
		}else{
			soJPPStrSQL = "insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_StatTime,MST_State)" +
			"select VehicleID,0,0,0,0,0,0,0,0,?,2 from V_VehicleInfo where Tmnl_SoftEdition in ("+soJPPSoftVerTerm+") and UsefulLife>=GETDATE() ";
		}
		baseDAO.execInsert(soJPPStrSQL, new Object[]{tTableDate});
	}
	private void makeEngONRunKmOilsOfPP(String tTableDate,boolean isJP,boolean isUDS) {
		String tableDate = tTableDate.replaceAll("-", "");
		//小一（PP）
		String soPPSoftVerTerm = EquipVersionCommon.getSoftVerByAgrType("Vcl_PP");
		String soPPStrSQL = null; 
		if(isJP){
			soPPStrSQL = "insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmMeter,MST_StatTime,MST_State) " +
			"select tmp.VehicleID,ISNULL(tmp.MsgT_tWorkTime_UDS-tmp2.MsgT_tWorkTime_UDS,0) EngON," +
//			"ISNULL(tmp.MsgT_tRunKm_UDS-tmp2.MsgT_tRunKm_UDS,0) RunKm," +
			"RunKm = 0," +
			"ISNULL(tmp.MsgT_tOilCons_UDS-tmp2.MsgT_tOilCons_UDS,0) Oils,null as iIdleOil," +
//			"ISNULL(tmp.MsgT_tRunKm_UDS-tmp2.MsgT_tRunKm_UDS,ISNULL(tmp.MsgU_tMeterDis - tmp2.MsgU_tMeterDis,0)) tRunkmMeter" +
			"ISNULL(tmp.MsgU_tMeterDis - tmp2.MsgU_tMeterDis,0) tRunkmMeter" +
			",?,2 " +
			"FROM (SELECT VehicleID," +
//			"MsgT_tRunKm_UDS = (select Top 1 MsgT_tRunKm_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm_UDS is not null and MsgT_tRunKm_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc ), " +
			"MsgT_tOilCons_UDS = (select Top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc ), "+
			"MsgT_tWorkTime_UDS = (select Top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc ), ";
			if(isUDS){
				soPPStrSQL += "MsgU_tMeterDis = (select top 1 Isnull(Convert(FLOAT,MsgUC_UDSValue),0) FROM  CTY_Egn_B.dbo.Msg_UDS_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" ON MsgUC_MsgU_ID = MsgU_ID where MsgU_Vcl_ID = VehicleID and MsgUC_UDSID = '3027' AND MsgUC_UDSValue IS NOT NULL and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime desc ) ";
			}else{
				soPPStrSQL += "MsgU_tMeterDis = 0 ";
			}
//			if(isUDS){
//				soPPStrSQL += ",MsgU_tMeterDis  ";
//			}
			soPPStrSQL += " FROM  V_VehicleInfo  ";
//			if(isUDS){
//				soPPStrSQL += "left join( select MsgU_Vcl_ID,ISNULL(CONVERT(float,MsgUC_UDSValue),0) as MsgU_tMeterDis from CTY_Egn_B.dbo.Msg_UDS_"+tableDate+" " +
//						"inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" on MsgUC_MsgU_ID=MsgU_ID  inner join ( select MAX(MsgUC_ID)MsgUCID from CTY_Egn_B.dbo.Msg_UDS_"+tableDate+"  " +
//						"inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" on MsgUC_MsgU_ID=MsgU_ID where MsgUC_UDSID='3027' and MsgUC_UDSValue is not null  group by MsgU_Vcl_ID  " +
//						" ) tmp on tmp.MsgUCID = MsgUC_ID  )tmpMeter on VehicleID=tmpMeter.MsgU_Vcl_ID ";
//			}
			soPPStrSQL +=  "WHERE  UsefulLife >= Getdate() AND Tmnl_SoftEdition IN ("+soPPSoftVerTerm+")) tmp  " +
			"INNER JOIN (SELECT VehicleID," +
//			"MsgT_tRunKm_UDS = (select Top 1 MsgT_tRunKm_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm_UDS is not null and MsgT_tRunKm_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc ), " +
			"MsgT_tOilCons_UDS = (select Top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc ), " +
			"MsgT_tWorkTime_UDS = (select Top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" where MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc ), ";
			if(isUDS){
				soPPStrSQL += "MsgU_tMeterDis = (select top 1 Isnull(Convert(FLOAT,MsgUC_UDSValue),0) FROM  CTY_Egn_B.dbo.Msg_UDS_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" ON MsgUC_MsgU_ID = MsgU_ID where MsgU_Vcl_ID = VehicleID and MsgUC_UDSID = '3027' AND MsgUC_UDSValue IS NOT NULL and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime ) ";
			}else{
				soPPStrSQL += "MsgU_tMeterDis = 0 ";
			}
			
//			if(isUDS){
//				soPPStrSQL += ",MsgU_tMeterDis  ";
//			}
			soPPStrSQL += " FROM  V_VehicleInfo  ";
//			if(isUDS){
//				soPPStrSQL += "left join( select MsgU_Vcl_ID,ISNULL(CONVERT(float,MsgUC_UDSValue),0) as MsgU_tMeterDis from CTY_Egn_B.dbo.Msg_UDS_"+tableDate+" " +
//						"inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" on MsgUC_MsgU_ID=MsgU_ID  inner join ( select min(MsgUC_ID)MsgUCID from CTY_Egn_B.dbo.Msg_UDS_"+tableDate+"  " +
//						"inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableDate+" on MsgUC_MsgU_ID=MsgU_ID where MsgUC_UDSID='3027' and MsgUC_UDSValue is not null  group by MsgU_Vcl_ID  " +
//						") tmp on tmp.MsgUCID = MsgUC_ID  )tmpMeter on VehicleID=tmpMeter.MsgU_Vcl_ID ";
//			}
			soPPStrSQL += "WHERE  UsefulLife >= Getdate() AND Tmnl_SoftEdition IN ("+soPPSoftVerTerm+") ) tmp2 ON tmp.VehicleID = tmp2.VehicleID;";
//			"from (select MsgT_Vcl_ID,MsgT_tRunKm_UDS,MsgT_tOilCons_UDS,MsgT_tWorkTime_UDS " +
//			"from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
//			"where MsgT_ID in (" +
//			"select MAX(MsgT_ID) from " +
//			"CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
//			"where MsgT_tRunKm_UDS is not null and MsgT_tRunKm_UDS>0 " +
//			"and MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS>0 " +
//			"and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS>0 " +
//			"and exists(select * from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE() " +
//			"and Tmnl_SoftEdition in ("+soPPSoftVerTerm+"))" +
//			"group by MsgT_Vcl_ID)" +
//			")tmp inner join(" +
//			"select MsgT_Vcl_ID,MsgT_tRunKm_UDS,MsgT_tOilCons_UDS,MsgT_tWorkTime_UDS " +
//			"from CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
//			"where MsgT_ID in (" +
//			"select MIN(MsgT_ID) from " +
//			"CTY_Egn_B.dbo.Msg_Timing_"+tableDate+" " +
//			"where MsgT_tRunKm_UDS is not null and MsgT_tRunKm_UDS>0 " +
//			"and MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS>0 " +
//			"and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS>0 " +
//			"and exists(select * from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE() " +
//			"and Tmnl_SoftEdition in ("+soPPSoftVerTerm+"))" +
//			"group by MsgT_Vcl_ID)" +
//			")tmp2 on tmp.MsgT_Vcl_ID=tmp2.MsgT_Vcl_ID";
		}else{
			soPPStrSQL = "insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmMeter,MST_StatTime,MST_State)" +
					"select VehicleID,0,0,0,0,0,?,2 from V_VehicleInfo where Tmnl_SoftEdition in ("+soPPSoftVerTerm+") and UsefulLife>=GETDATE() ";
		}
		baseDAO.execInsert(soPPStrSQL, new Object[]{tTableDate});
	}
	private void makeEngONRunKmOilsOfJ(String tTableDate) {
		String tableDate = tTableDate.replaceAll("-", "");
		//小一（J）
		String soJSoftVerTerm = EquipVersionCommon.getSoftVerByAgrType("Vcl_J");
		
		Map<String,Object> msgCan = baseDAO.execQueryOne(strSQL_B, new Object[]{"Msg_CAN_Content_"+tableDate+""});
		if("1".equals(MapGetter.getString(msgCan, "counts"))){
			String selVclSQL403 = "select VehicleID from V_VehicleInfo where UsefulLife>=GETDATE() and Tmnl_SoftEdition in ("+soJSoftVerTerm+");";
			List<Map<String,Object>> vclList403 = baseDAO.execQuery(selVclSQL403, new Object[]{});			
			for(Map<String,Object> vclMap403:vclList403){
				String vclId403 = MapGetter.getString(vclMap403,"VehicleID");
				StringBuffer strBuff403 = new StringBuffer();
				strBuff403.append("insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons, MST_iIdleOil,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_StatTime,MST_State) ");
				strBuff403.append("select tmpz.VehicleID,ISNULL(tmpz.ECM-tmpz2.ECM,0) EngON,ISNULL(tmpz.tETDistance-tmpz2.tETDistance,0) RunKm,ISNULL(tmpz.tOilCons-tmpz2.tOilCons,0) Oils,Isnull(tmpz.tIdleOil - tmpz2.tIdleOil,0) iIdleOil," +
				        "ISNULL(tmpz.tKm1-tmpz2.tKm1,0) tRunKmExact,ISNULL(tmpz.tKm2-tmpz2.tKm2,0) tRunKm,ISNULL(tmpz.tKm3-tmpz2.tKm3,0) tRunKmECU,ISNULL(tmpz.tKm4-tmpz2.tKm4,0) tRunKmMeter,"+
						"'"+tTableDate+"',2 from ( ");
				strBuff403.append("select *,tETDistance=case when can.tKm2 is not null then can.tKm2 when can.tKm1 is not null then can.tKm1 else isnull(can.tKm3,0) end ");
				strBuff403.append("from ( SELECT VehicleID,ECM = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tOilCons = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tIdleOil = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 24  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tKm1= (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tKm2 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tKm3 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
				strBuff403.append("tKm4 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc) ");
				strBuff403.append("FROM  V_VehicleInfo where VehicleID = '"+vclId403+"' )can )tmpz  ");
				strBuff403.append("INNER JOIN (select *,tETDistance=case when can.tKm2 is not null then can.tKm2 when can.tKm1 is not null then can.tKm1 else isnull(can.tKm3,0) end ");
				strBuff403.append("from ( SELECT VehicleID,ECM = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tOilCons = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tIdleOil = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 24  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tKm1= (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tKm2 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tKm3 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
				strBuff403.append("tKm4 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" ON MsgC_ID = MsgCCo_MsgC_ID ");
				strBuff403.append("WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc) ");
				strBuff403.append("FROM  V_VehicleInfo where VehicleID = '"+vclId403+"' )can) tmpz2 ON tmpz.VehicleID = tmpz2.VehicleID ");
				/*strBuff403.append("select top 1 tTime.MsgC_Vcl_ID, tTime.tTime ECM, tOil.tOil tOilCons," +
					"tETDistance=case when tKm2.tKm2 is not null then tKm2.tKm2 when tKm1.tKm1 is not null then tKm1.tKm1 else isnull(tKm3.tKm3,0) end,tKm1,tKm2,tKm3,tKm4 from ");
				strBuff403.append("(select MsgC_ID,MsgCCo_ParmValue tTime,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=20 and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tTime left join( ");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tOil,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=22  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tOil on tTime.MsgC_ID=tOil.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm1,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=27  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm1 on tOil.MsgC_ID=tKm1.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm2,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=28  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm2 on tKm1.MsgC_ID=tKm2.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm3,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=29  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm3 on tKm2.MsgC_ID=tKm3.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm4,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=53  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm4 on tKm3.MsgC_ID=tKm4.MsgC_ID ");
				
				strBuff403.append("where tTime.tTime is not null and tTime.tTime>0 ");
				strBuff403.append("and tOil.tOil is not null and tOil.tOil>0 ");
				strBuff403.append("and tKm4.tKm4 is not null and tKm4.tKm4>0 ");
				strBuff403.append("and not(tKm1.tKm1 is null and tKm2.tKm2 is null and tKm3.tKm3 is null) ");
				strBuff403.append("and not(tKm1.tKm1<0 and tKm2.tKm2<0 and tKm3.tKm3<0)");
				strBuff403.append("order by tTime.MsgC_ID desc");
				strBuff403.append(")tmpz inner join (");
				strBuff403.append("select top 1 tTime.MsgC_Vcl_ID, tTime.tTime ECM, tOil.tOil tOilCons," +
					"tETDistance=case when tKm2.tKm2 is not null then tKm2.tKm2 when tKm1.tKm1 is not null then tKm1.tKm1 else isnull(tKm3.tKm3,0) end ,tKm1,tKm2,tKm3,tKm4 from ");
				strBuff403.append("(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tTime,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=20 and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tTime ");
				strBuff403.append("left join( ");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tOil,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=22  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tOil on tTime.MsgC_ID=tOil.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm1,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=27  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm1 on tOil.MsgC_ID=tKm1.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm2,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=28  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm2 on tKm1.MsgC_ID=tKm2.MsgC_ID ");
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm3,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=29  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm3 on tKm2.MsgC_ID=tKm3.MsgC_ID ");
				
				strBuff403.append("left join(");
				strBuff403.append("select MsgC_ID,MsgCCo_ParmValue tKm4,MsgC_Vcl_ID from CTY_Egn_B.dbo.Msg_CAN_"+tableDate+" ");
				strBuff403.append("inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableDate+" on MsgC_ID=MsgCCo_MsgC_ID where MsgCCo_SysCP_ID=53  and MsgC_Vcl_ID="+vclId403+" ");
				strBuff403.append(")tKm4 on tKm2.MsgC_ID=tKm3.MsgC_ID ");
				
				strBuff403.append("where tTime.tTime is not null and tTime.tTime>0 ");
				strBuff403.append("and tOil.tOil is not null and tOil.tOil>0 ");
				strBuff403.append("and tKm4.tKm4 is not null and tKm4.tKm4>0 ");
				strBuff403.append("and not(tKm1.tKm1 is null and tKm2.tKm2 is null and tKm3.tKm3 is null) ");
				strBuff403.append("and not(tKm1.tKm1<0 and tKm2.tKm2<0 and tKm3.tKm3<0)");
				strBuff403.append("order by tTime.MsgC_ID asc");
				strBuff403.append(")tmpz2 on tmpz.MsgC_Vcl_ID=tmpz2.MsgC_Vcl_ID ");*/
				baseDAO.execInsert(strBuff403.toString(), new Object[]{});
			}
		}else{
			StringBuffer str403 = new StringBuffer();
			str403.append("insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_StatTime,MST_State)");
			str403.append("select VehicleID,0,0,0,0,0,0,0,0,'"+tTableDate+"',2 from V_VehicleInfo where Tmnl_SoftEdition in ("+soJSoftVerTerm+") and UsefulLife>=GETDATE() ");
			baseDAO.execInsert(str403.toString(), new Object[]{});
		}
	}
	private void makeEngONRunKmOilsOfBoAll(String tTableDate) {
		String tableDate = tTableDate.replaceAll("-", "");
		
		//大一
		String boAllSoftVerTerm = EquipVersionCommon.getSoftVerByAgrType("Vcl_D");
		Map<String,Object> map_c = baseDAO.execQueryOne(strSQL_A, new Object[]{"Msg_Timing_"+tableDate+""});
		StringBuffer boStrSQL = new StringBuffer();
		if("1".equals(MapGetter.getString(map_c,"counts"))){
			boStrSQL.append("insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil," +
		                    "MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_StatTime,MST_State)");
			boStrSQL.append("select tmp.VehicleID,ISNULL(tmp.ECM-tmp2.ECM,0) EngON,ISNULL(tmp.ETDistance-tmp2.ETDistance,0) RunKm ,ISNULL(tmp.tOilCons-tmp2.tOilCons,0) Oils,null as iIdleOil, ");
			boStrSQL.append("ISNULL(tmp.MsgT_tRunKm-tmp2.MsgT_tRunKm,0) tRunKmExact,ISNULL(tmp.MsgT_tRunKm1-tmp2.MsgT_tRunKm1,0) tRunKm,ISNULL(tmp.MsgT_tRunKmECU-tmp2.MsgT_tRunKmECU,0) tRunKmECU, ");
			boStrSQL.append("?,2 from ( select ETDistance = CASE WHEN MsgT_tRunKm1 IS NOT NULL  THEN MsgT_tRunKm1 WHEN MsgT_tRunKm1 IS NULL  AND MsgT_tRunKm IS NOT NULL  THEN MsgT_tRunKm ELSE Isnull(MsgT_tRunKmECU,0)END,* from ( ");
			boStrSQL.append("SELECT VehicleID,ECM = (select top 1 MsgT_tEWork from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tEWork is not null and MsgT_tEWork >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			boStrSQL.append("tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tOilCons is not null and MsgT_tOilCons>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			boStrSQL.append("MsgT_tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm is not null and MsgT_tRunKm>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			boStrSQL.append("MsgT_tRunKm1 = (select top 1 MsgT_tRunKm1 from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm1 is not null and MsgT_tRunKm1>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			boStrSQL.append("MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKmECU is not null and MsgT_tRunKmECU>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc) ");
			boStrSQL.append("FROM  V_VehicleInfo  WHERE UsefulLife >= GETDATE() AND Tmnl_SoftEdition IN ("+boAllSoftVerTerm+") )bo)tmp ");
			boStrSQL.append("INNER JOIN (select ETDistance = CASE WHEN MsgT_tRunKm1 IS NOT NULL  THEN MsgT_tRunKm1 WHEN MsgT_tRunKm1 IS NULL  AND MsgT_tRunKm IS NOT NULL  THEN MsgT_tRunKm ELSE Isnull(MsgT_tRunKmECU,0)END,* from ( ");
			boStrSQL.append("SELECT VehicleID,ECM = (select top 1 MsgT_tEWork from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tEWork is not null and MsgT_tEWork >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc), ");
			boStrSQL.append("tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tOilCons is not null and MsgT_tOilCons>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc), ");
			boStrSQL.append("MsgT_tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm is not null and MsgT_tRunKm>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc), ");
			boStrSQL.append("MsgT_tRunKm1 = (select top 1 MsgT_tRunKm1 from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKm1 is not null and MsgT_tRunKm1>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc), ");
			boStrSQL.append("MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" where MsgT_tRunKmECU is not null and MsgT_tRunKmECU>0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc) ");
			boStrSQL.append("FROM V_VehicleInfo  WHERE   UsefulLife >= GETDATE() AND Tmnl_SoftEdition IN ("+boAllSoftVerTerm+") )bo2)tmp2 ON tmp.VehicleID = tmp2.VehicleID ");
			/*boStrSQL.append("?,2 from (select MsgT_Vcl_ID VehicleID,MsgT_tEWork ECM,");
			boStrSQL.append("ETDistance=case when MsgT_tRunKm1 is not null then MsgT_tRunKm1 ");
			boStrSQL.append("when MsgT_tRunKm1 is null and MsgT_tRunKm is not null then MsgT_tRunKm else ISNULL(MsgT_tRunKmECU,0) end,");
			boStrSQL.append("MsgT_tOilCons tOilCons,MsgT_tRunKm,MsgT_tRunKm1,MsgT_tRunKmECU from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" ");
			boStrSQL.append("where MsgT_ID in (select MAX(MsgT_ID) from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" ");
			boStrSQL.append("where not(MsgT_tRunKm1 is null and MsgT_tRunKm is null and MsgT_tRunKmECU is null) and (MsgT_tRunKm1>0 or MsgT_tRunKm>0 or MsgT_tRunKmECU>0) ");
			boStrSQL.append("and MsgT_tOilCons is not null and MsgT_tOilCons>0 and MsgT_tEWork is not null and MsgT_tEWork>0 ");
			boStrSQL.append("and exists(select 1 from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE() and Tmnl_SoftEdition in ("+boAllSoftVerTerm+")) ");
			boStrSQL.append("group by MsgT_Vcl_ID))tmp inner join (");
			boStrSQL.append("select MsgT_Vcl_ID VehicleID,MsgT_tEWork ECM,");
			boStrSQL.append("ETDistance=case when MsgT_tRunKm1 is not null then MsgT_tRunKm1 ");
			boStrSQL.append("when MsgT_tRunKm1 is null and MsgT_tRunKm is not null then MsgT_tRunKm else ISNULL(MsgT_tRunKmECU,0) end,");
			boStrSQL.append("MsgT_tOilCons tOilCons,MsgT_tRunKm,MsgT_tRunKm1,MsgT_tRunKmECU from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" ");
			boStrSQL.append("where MsgT_ID in (select MIN(MsgT_ID) from CTY_Egn_A.dbo.Msg_Timing_"+tableDate+" ");
			boStrSQL.append("where not(MsgT_tRunKm1 is null and MsgT_tRunKm is null and MsgT_tRunKmECU is null) and (MsgT_tRunKm1>0 or MsgT_tRunKm>0 or MsgT_tRunKmECU>0) ");
			boStrSQL.append("and MsgT_tOilCons is not null and MsgT_tOilCons>0 and MsgT_tEWork is not null and MsgT_tEWork>0 ");
			boStrSQL.append("and exists(select 1 from V_VehicleInfo where VehicleID=MsgT_Vcl_ID and UsefulLife>=GETDATE()  and Tmnl_SoftEdition in ("+boAllSoftVerTerm+")) ");
			boStrSQL.append("group by MsgT_Vcl_ID))tmp2 on tmp.VehicleID=tmp2.VehicleID ");*/
		}else{
			boStrSQL.append("insert into Message_Stat_Today_Tmp(MST_VclID,MST_WorkHours,MST_ETDistance,MST_OilCons,MST_iIdleOil," +
					 "MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_StatTime,MST_State)");
			boStrSQL.append("select VehicleID,0,0,0,0,0,0,0,?,2 from V_VehicleInfo where Tmnl_SoftEdition in ("+boAllSoftVerTerm+") and UsefulLife>=GETDATE() ");
		}
		baseDAO.execInsert(boStrSQL.toString(), new Object[]{tTableDate});	
		
	}
	public void updateData(){
		List<String> sqlList = new ArrayList<String>();
		sqlList.add("update Message_Stat_Today_Tmp set MST_WorkHours = 0 where MST_WorkHours < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_OilCons = 0 where MST_OilCons < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_iIdleOil = 0 where MST_iIdleOil < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_ETDistance = 0 where MST_ETDistance < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_tRunKmExact = 0 where MST_tRunKmExact < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_tRunKm = 0 where MST_tRunKm < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_tRunKmECU = 0 where MST_tRunKmECU < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_tRunKmMeter = 0 where MST_tRunKmMeter < 0;");
		sqlList.add("update Message_Stat_Today_Tmp set MST_tRunKmGPS = 0 where MST_tRunKmGPS < 0;");
		//		sqlList.add("update Message_Stat_Today_Tmp set MST_State=1 where MST_State=2");
		tranDAO.batch(sqlList);
		String sql1 = "truncate table Message_Stat_Today";
		this.baseDAO.execUpdate(sql1, new Object[]{});
		String sql0 = "insert into Message_Stat_Today(MST_VclID,MST_WorkHours,MST_OilCons,MST_iIdleOil,MST_ETDistance,MST_StatTime,MST_State,MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_tRunKmGPS)select MST_VclID,MST_WorkHours," +
				"MST_OilCons,MST_iIdleOil,MST_ETDistance,MST_StatTime,'1',MST_tRunKmExact,MST_tRunKm,MST_tRunKmECU,MST_tRunKmMeter,MST_tRunKmGPS from Message_Stat_Today_Tmp ";
		this.baseDAO.execInsert(sql0, new Object[]{});
	}
	
	public void trunData(){
		String strSQL = "truncate table Message_Stat_Today_Tmp";
		baseDAO.execUpdate(strSQL, new Object[]{});
	}
}